#include <stdio.h>
#include <string.h>

#define STDIN
//#define DEBUG

#define MAX_LEN 200

int n;
int k;
char msg[MAX_LEN+1];
char result[MAX_LEN+1];
int key[MAX_LEN][2];

void empty()
{
    memset(msg, ' ', sizeof(msg));
    memset(result, ' ', sizeof(result));
}

void process()
{
    int i;
#ifdef DEBUG
    for (i = 0; i < n; ++i)
    {
        printf("%d ", key[i][0]);
    }
    printf("\n");
#endif
    for (i=0;msg[i]&& msg[i]!=10;i++);
    for (;i<n;i++) msg[i]=' ';
#ifdef DEBUG
    printf("k: %d\n", k);
    printf("%s|len: %d\n", msg, strlen(msg));
#endif

    for (i = 0; i < n; ++i)
        key[i][1] = 0;

    int select = 0;
    while(1)
    {
        while(key[select][1] == 1)
            select++;
        if (select >= n)
            break;
        int next = select;
        int idx[MAX_LEN];
        int len = 0;
        do
        {
            len++;
            next = key[next][0];
            key[next][1] = 1;
            idx[len-1] = next;
        }while(next != select);
#ifdef DEBUG
        printf("len: %d\n", len);
        {
            int i;
            for (i = 0; i < len; ++i)
                printf("%d ", idx[i]);
            printf("\n");
        }
#endif

        int strip = k % len;
        int i;
        for (i = 0; i < len; ++i)
        {
            next = idx[ (i + strip) % len];
            result[next] = msg[idx[i]];
        }
    }

    result[n] = '\0';
#ifdef DEBUG
    printf("%s|lenthg: %d\n", result, strlen(result));
#endif
    printf("%s\n", result);

}


int main()
{
#ifdef STDIN
    freopen("bin/1026.in", "r", stdin);
#endif

    while(1)
    {
        scanf("%d", &n);
        if (n == 0)
            break;
        int i;
        for (i = 0; i < n; ++i)
        {
            scanf("%d", &key[i][0]);
            key[i][0] -= 1;
        }
        while(1)
        {
            scanf("%d%*c", &k);
            if (k == 0)
                break;

            empty();
            gets(msg);

            process();

        }
        printf("\n");
    }
    return 0;
}
